﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESP
{
    //////////////////////////////////////////////////////////////////////
//   Alan Oursland  
// 
//   ESP Java implementation.
//
//	 This code is a direct port of Faustino Gomez's ESP code
//   that was code started from Daniel Polani's translation of 
//   Dave Moriarty's original SANE code from C to C++.
//   
//   $Log: Neuron.java,v $
//////////////////////////////////////////////////////////////////////////
    public class Neuron : ICloneable
    {
        public double[] weight;
//	public double[] delta;
        public double fitness; //neuron's fitness value
        public int tests; //holds the total # of networks participated in
        public double activation; //neuron's activation level 
        public bool lesioned = false;

        //constructor
        public Neuron(int numNeurons)
        {
            weight = new double[numNeurons]; //fill weight vector with zeros
        }

        public Object Clone()
        {
            try
            {
                Neuron rc = (Neuron) this.MemberwiseClone();
                rc.weight = (double[]) rc.weight.Clone();
                return rc;
            }
            catch (NotSupportedException e)
            {
                return null;
            }
        }

/*	
	public Neuron(final Neuron n) {
		weight = new double[n.weight.Length];	
		for( int i=0; i < weight.Length; i++ ) {
			weight[i] = n.weight[i];
		}
//		delta = new double[n.delta.Length];	
//		for( int i=0; i < delta.Length; i++ ) {
//			delta[i] = n.delta[i];
//		}
		fitness = n.fitness;
		tests = n.tests;
		activation = n.activation;
		lesioned = n.lesioned;
	}
*/

        public void create()
        {
            for (int i = 0; i < weight.Length; ++i)
            {
                weight[i] = (RandomSingleton.getInstance().NextDouble()*12.0) - 6.0;
            }
        }

        private RandomCauchy rndCauchy = new RandomCauchy();

        public void perturb(Neuron n)
        {
            perturb(n, rndCauchy, 0.3);
        }

        public void perturb(Neuron n, RandomFunction randFn, double coeff)
        {
            for (int i = 0; i < weight.Length; ++i)
            {
                weight[i] = n.weight[i] + randFn.randomFunction(coeff);
            }
        }
    }
}
